package com.yk.faceapplication.util;

import android.text.InputFilter;
import android.text.Spanned;

public class InputFilterMinMax implements InputFilter {

    private double min, max;

    public InputFilterMinMax(double min, double max) {
        this.min = min;
        this.max = max;
    }

    public InputFilterMinMax(String min, String max) {
        this.min = Double.parseDouble(min);
        this.max = Double.parseDouble(max);
    }

    @Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {   
        try {
            int input = Integer.parseInt(dest.toString() + source.toString());
            LogDebugger.info("input:"+input);
            LogDebugger.info("max:"+max);
            LogDebugger.info("min:"+min);
//            if(input != 0){
//            	return null;
//            }
            if (input <= max && input >= min)
                return null;
        } catch (NumberFormatException nfe) { }     
        return "";
    }

    private boolean isInRange(int min, int max, int c) {
        return max > min ? c >= min && c <= max : c >= max && c <= min;
    }
}